package com.interceptor;

import net.bytebuddy.implementation.bind.annotation.AllArguments;
import net.bytebuddy.implementation.bind.annotation.Origin;
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.SuperCall;

public class DelegateLogic {

    /**
     * 参数/返回值类型必须与原方法兼容；
     * 参数名可随意，用 @Origin 可拿到 Method 对象，用 @SuperCall 可调用原实现
     */
    @RuntimeType
    public static Object handle(@Origin java.lang.reflect.Method method,
                                @AllArguments Object[] args,
                                @SuperCall java.util.concurrent.Callable<Object> original) {
        System.out.println("agent=========DelegateLogic.handle()");

        // 1. 完全替换原逻辑 -----------------
        try {
            return   original.call();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}